import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '@/utils/storage.js'

Vue.use(Vuex)

export default new Vuex.Store({
  name: 'stateStore',
  state: {
    // 获取保存起来的token 使state的状态持久化
    user: getItem('user')
  },
  mutations: {
    setUser (state, userToken) {
      state.user = userToken
      // 防止刷新后 丢失state的状态 把token保存起来
      setItem('user', userToken)
    }
  },
  actions: {
  },
  modules: {
  }
})
